package com.ztgf.order.api.cms;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.utils.ExcelExport2;
import com.ztgf.order.models.bo.OrderShopStatisticsBO;
import com.ztgf.order.models.bo.OrderStatisticsBO;
import com.ztgf.order.models.service.IOrderCommodityStatisticsService;
import com.ztgf.order.models.vo.OrderCommodityStatisticsShopVO;
import com.ztgf.order.models.vo.OrderCommodityStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * author: chenyu.wang
 * date: 2020-07-24 15:19
 * Description:后台管理系统产品统计控制器
 */
@RestController
@RequestMapping("/cms/orderCommodityStatisticsController")
@Api(value = "OrderCommodityStatisticsController", tags = "后台管理系统产品统计接口")
public class OrderCommodityStatisticsController {

    @DubboReference
    private IOrderCommodityStatisticsService iOrderCommodityStatisticsService;

    @PostMapping(value = "/queryCommodityTotal")
    @ApiOperation(value = "当前平台商品总量", notes = "当前平台商品总量")
    public Result queryCommodityTotal() {
        Integer total = iOrderCommodityStatisticsService.queryCommodityTotal();
        return new Result<>(total);
    }

    @PostMapping(value = "/queryCategoryGoods")
    @ApiOperation(value = "后台管理系统产品统计各类目整体商品统计", notes = "后台管理系统产品统计各类目整体商品统计")
    public Result queryCategoryGoods(OrderStatisticsBO bo) {
        Page<OrderCommodityStatisticsVO> page = iOrderCommodityStatisticsService.queryCategoryGoods(bo);
        return new Result<>(page);
    }

    @PostMapping(value = "/queryShopCategoryGoodsNum")
    @ApiOperation(value = "后台管理系统产品统计店铺类目商品数量", notes = "后台管理系统产品统计店铺类目商品数量")
    public Result queryShopCategoryGoodsNum(OrderShopStatisticsBO bo) {
        Page<OrderCommodityStatisticsShopVO> page = iOrderCommodityStatisticsService.numberOfProductsInStoreCategory(bo);
        return new Result<>(page);
    }

    @GetMapping(value = "/exportCategoryGoods")
    @ApiOperation(value = "产品统计各类目整体商品统计导出", notes = "产品统计各类目整体商品统计导出")
    public void exportCategoryGoods(HttpServletResponse response) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"编号", "类目名称", "类目级别", "商品数量"};
        //查询数据
        OrderStatisticsBO bo = new OrderStatisticsBO();
        bo.setPageNo(0);
        bo.setPageSize(1000);
        Page<OrderCommodityStatisticsVO> page = iOrderCommodityStatisticsService.queryCategoryGoods(bo);
        List<OrderCommodityStatisticsVO> list = page.getRecords();
        ExcelExport2.export(response, list, attributeNames, "_各类目整体销售额");
    }

    @GetMapping(value = "/exportShopCategoryGoodsNum")
    @ApiOperation(value = "产品统计店铺类目商品数量导出", notes = "产品统计店铺类目商品数量导出")
    public void exportShopCategoryGoodsNum(HttpServletResponse response) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"编号", "类目编号", "店铺名称", "类目名称", "商品数量"};
        //查询数据
        OrderShopStatisticsBO bo = new OrderShopStatisticsBO();
        bo.setPageNo(0);
        bo.setPageSize(1000);
        Page<OrderCommodityStatisticsShopVO> page = iOrderCommodityStatisticsService.numberOfProductsInStoreCategory(bo);
        List<OrderCommodityStatisticsShopVO> list = page.getRecords();
        ExcelExport2.export(response, list, attributeNames, "_各类产品统计店铺类目商品数量");
    }
}
